/* The file is saved in UTF-8 codepage.
 * Check: «Stereotype», Section mark-§, Copyright-©, Alpha-α, Beta-β, Smile-☺
 */
package cz.pecinovsky.english.lootp._125_;

import cz.pecinovsky.english.lootp._000_.Run;

import cz.pecinovsky.english.lootp.manager.Rectangle;
import cz.pecinovsky.english.lootp.manager.Mover;


import cz.pecinovsky.english.lootp.manager.CanvasManager_Envelope.               CanvasManager;
import cz.pecinovsky.english.lootp._125_.Arrow_125_133.                          Arrow;
import cz.pecinovsky.english.lootp._125_.TestUtility_129_133.                    TestUtility;


////////////////////////////////////////////////////////////////////////////////
//%%+  +++++ End of ignored starting test - place for imports +++++
//%I+ =133c
//
//import správce.*;
//%I-
//%I+ >=133z
//
//import cz.pecinovsky.english.lootp.canvasmanager.Rectangle;
//import cz.pecinovsky.english.lootp.canvasmanager.Mover;
//import cz.pecinovsky.english.lootp.canvasmanager.CanvasManager;
//
//%I-
//%A+ >=133z
import cz.pecinovsky.english.lootp.utility.NamedColor;
import cz.pecinovsky.english.lootp.utility.IO;
import cz.pecinovsky.english.lootp.utility.Position;
//%A-
//%X+ xxxxx Start of the ovejumped text with declaration of the envelope xxxxx
/*******************************************************************************
 *<pre>
 * Předchozí: Není__Toto_je_nově_definovaná_třída
 *
 * Přidáno:
 *      *
 * Upraveno:
 *      *
 *</pre>
 */
public class ArrowTest_125_133
{ static
////////////////////////////////////////////////////////////////////////////////
//%X- ----- End of the ovejumped text with declaration of the envelope -----


/*******************************************************************************
 * Testovací třída {@code ArrowTest}  slouží ke komplexnímu otestování
 * třídy {@link ArrowTest}.
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
public class ArrowTest extends junit.framework.TestCase
{
    private CanvasManager CM;
    private Arrow arrow0;
    private Arrow arrowXY;
    private Arrow arrowXYB;
    private Arrow arrowXYM;
    private Arrow arrowXYMB;



//== CONSTANT CLASS ATTRIBUTES =================================================
//== VARIABLE CLASS ATTRIBUTES =================================================
//== STATIC CONSTRUCTOR (CLASS INITIALIZER, STATIC INICITALIZING BLOCK) ========
//== CONSTANT INSTANCE ATTRIBUTES ==============================================
//== VARIABLE INSTANCE ATTRIBUTES ==============================================
//== CLASS GETTERS AND SETTERS =================================================
//== OTHER NON-PRIVATE CLASS METHODS ===========================================

//##############################################################################
//== CONSTUCTORS AND FACTORY METHODS ===========================================

    /***************************************************************************
     * Vytvoří test se zadaným názvem.
     *
     * @param name  Název konstruovaného testu
     */
    public ArrowTest(String name)
    {
        super(name);
    }



//== PREPARATION AND CLEANING THE FIXTURE ======================================

    /***************************************************************************
     * Inicializace předcházející spuštění každého testu a připravující tzv.
     * přípravek (fixture), což je sada objektů, s nimiž budou testy pracovat.
     */
    @Override
    protected void setUp()
    {
        arrow0     = new Arrow();
        arrowXY    = new Arrow(50,  50);
        arrowXYB   = new Arrow(100, 100, NamedColor.BLUE);
        arrowXYM   = new Arrow( 0, 100, 100);
        arrowXYMB  = new Arrow(100,   0, 100, NamedColor.BLUE);

        CM = CanvasManager.getInstance();
        CM.add(arrow0);
        CM.add(arrowXY);
        CM.add(arrowXYB);
        CM.add(arrowXYM);
        CM.add(arrowXYMB);

//%A+ >126
        System.out.println("\n====== Instance v přípravku pro " + this +
                           "\n| CM:        " + CM +
                           "\n| arrow0:    " + arrow0 +
                           "\n| arrowXY:   " + arrowXY +
                           "\n| arrowXYB:  " + arrowXYB +
                           "\n| arrowXYM : " + arrowXYM +
                           "\n| arrowXYMB: " + arrowXYMB +
                           "\n======");
//%A-
        IO.inform("Arrows prepared");
    }


    /***************************************************************************
     * Úklid po testu - tato metoda se spustí po vykonání každého testu.
     */
    @Override
    protected void tearDown()
    {
    }


//== PRIVATE AND AUXILIARY CLASS METHODS =======================================
//== PRIVATE AND AUXILIARY INSTANCE METHODS ====================================
//%I+ <129
//
//    /***************************************************************************
//     * Za pomoci přesouvače plynule prohodí pozice zadaných šipek.
//     *
//     * @param s1 První arrow
//     * @param s2 Druhá arrow
//     */
//    private void auxSmoothlySwapPositions(Arrow s1, Arrow s2)
//    {
//        Mover mover = new Mover(10);
//        Position p1 = s1.getPosition();
//        s1.translucent();
//        s2.translucent();
//        mover.moveTo(s2.getPosition(), s1);
//        mover.moveTo(p1,             s2);
//        s1.restoreColor();
//        s2.restoreColor();
//    }
//
//
//    /***************************************************************************
//     * Vyzkouší změny pozice a velikosti zadané šipky
//     *
//     * @param s Testovaná arrow
//     */
//    private void auxPositionSize(Arrow s)
//    {
//        final int ms = 500;
//        s.setPosition(150, 150);
//        IO.pause(ms);
//        s.setModule(150);
//        IO.pause(ms);
//        s.setModule(25);
//        IO.pause(ms);
//        CM.remove(s);
//        IO.pause(ms);
//    }
//
//%I-
//%A+ >127

    /***************************************************************************
     * Prohodí pozice zadaných šipek a nechá zkontrolovat,
     * zda si šipky své pozice doopravdy vyměnily.
     *
     * @param s1 První arrow
     * @param s2 Druhá arrow
     */
    private void auxSwapPositionsWithCheck(Arrow s1, Arrow s2)
    {
//%A-
//%I+ >127 <129
//        Position p1 = s1.getPosition();
//        Position p2 = s2.getPosition();
//
//        System.out.println("Výchozí: " + p1 + " <--> " + p2);
//        auxSmoothlySwapPositions(s1, s2);
//        System.out.println("Cílová:  " + s1.getPosition() +
//                              " <--> " + s2.getPosition() + "\n");
//
//        assertEquals(p1, s2.getPosition());
//        assertEquals(p2, s1.getPosition());
//%I-
//%A+ >129
        s1.translucent();
        s2.translucent();
        TestUtility.swapPositionsWithCheck(s1, s2);
        s1.restoreColor();
        s2.restoreColor();
//%A-
//%A+ >127
    }

//%A-


//== EMBEDDED TYPES AND INNER CLASSES ==========================================
//== THE TESTS =================================================================
//
//     /***************************************************************************
//      *
//      */
//     public void testXXX()
//     {
//     }


    public void testTranslucent()
    {
        Rectangle ground = new Rectangle(25, 25, 100, 100, NamedColor.WHITE);
        CM.addBehind(arrow0, ground);

        arrow0   .translucent();
        arrowXY  .translucent();
        arrowXYB .translucent();
        arrowXYM .translucent();
        arrowXYMB.translucent();

        IO.inform("Verify translucency");

        arrow0   .restoreColor();
        arrowXY  .restoreColor();
        arrowXYB .restoreColor();
        arrowXYM .restoreColor();
        arrowXYMB.restoreColor();
     }


    public void testSmoothMovement()
    {
        arrow0   .translucent();
        arrowXY  .translucent();
        arrowXYB .translucent();
        arrowXYM .translucent();
        arrowXYMB.translucent();
        Mover p = new Mover(10);
        p.moveTo(250,   0, arrow0);
        p.moveTo(250,  50, arrowXY);
        p.moveTo(250, 100, arrowXYB);
        p.moveTo(200, 100, arrowXYM);
        p.moveTo(200,   0, arrowXYMB);
    }

//%I+ <129
//
//    public void testSmoothlySwapPositions()
//    {
//        auxSmoothlySwapPositions(arrowXYMB, arrowXYM);
//        auxSmoothlySwapPositions(arrowXYB,  arrow0);
//    }
//
//%I-

    public void testPositionSize()
    {
//%I+ <129
//        auxPositionSize(arrow0);
//        auxPositionSize(arrowXY);
//        auxPositionSize(arrowXYB);
//        auxPositionSize(arrowXYM);
//        auxPositionSize(arrowXYMB);
//%I-
//%A+ >129
        Position sem = new Position(150, 150);
        int small   = 25;
        int big  = 150;

        TestUtility.positionSize(arrow0,    sem, small, big);
        TestUtility.positionSize(arrowXY,   sem, small, big);
        TestUtility.positionSize(arrowXYB,  sem, small, big);
        TestUtility.positionSize(arrowXYM,  sem, small, big);
        TestUtility.positionSize(arrowXYMB, sem, small, big);
//%A-
    }
//%A+ >127


    public void testSwapPositionsWithCheck()
    {
        auxSwapPositionsWithCheck(arrow0,   arrowXYMB);
        auxSwapPositionsWithCheck(arrowXYB, arrowXYM);
        auxSwapPositionsWithCheck(arrowXYM, arrow0);
    }
//%A-
//%X+
     /** */
     public void testFixture() {}
//%X-
}

//%%- ---- Start of the ovejumped text with closing of the envelope ----
//== TESTING CLASSES AND METHODS ===============================================
    private ArrowTest_125_133() {}

    /***************************************************************************
     * Třída, jejíž instance má na starosti úklid mezi jednotlivými testy,
     * který není možno zakomponovat do metody {@code tearDown()},
     * dokud nebudou studenti umět programovat.
     */
    private static class TearDown implements Run.ITD
    {
        /** {@inheritDoc} */
        @Override
        public void cleanUp()
        {
//            Canvas.clearCanvas();
//            CanvasManager.getInstance().removeAll();
        }
    }


    /***************************************************************************
     * Test method.
     */
    public static void test()
    {
        Run.tests(ArrowTest.class,
                new TearDown(),
//                "testFixture",
//                "testTranslucent",
                "testPositionSize",
//                "testSmoothMovement",
//                "testSmoothlySwapPositions",
                "testSwapPositionsWithCheck",
                "");
        System.exit(0);
    }
    /** @param args Parametry příkazového řádku - nepoužívané. */
    public static void main(String[] args)  {  test();  }
}
